/*
	Name: 普通平衡树
	Author: There,hello 
	Date: 05-11-19 8:40
	Description: Luogu P3369 
	Algorithm: vector 
*/
#include <bits/stdc++.h>
using namespace std;
vector<int> q;
int n;
int main()
{
    scanf("%d", &n);
    int x, y;
    while (n--)
    {
        scanf("%d%d", &x, &y);
        if (x == 1)
            q.insert(lower_bound(q.begin(), q.end(), y), y);
        if (x == 2)
            q.erase(lower_bound(q.begin(), q.end(), y));
        if (x == 3)
            printf("%d\n", (lower_bound(q.begin(), q.end(), y) - q.begin()) + 1);
        if (x == 4)
            printf("%d\n", q.at(y - 1));
        if (x == 5)
            printf("%d\n", *(--lower_bound(q.begin(), q.end(), y)));
        if (x == 6)
            printf("%d\n", *upper_bound(q.begin(), q.end(), y));
    }
}